<template>
	<view class="page" :style="{'--color': color}">
		<status-bar title="全部订单"></status-bar>
		<view class="Wrapper">
			<view class="row j-sb a-center">
				<text class="black size30 bold">订单/流水</text>
				<view class="d-flex a-center" @click="show = true">
					<text class="color_33 size28">{{ monthData }}</text>
					<view class="iconfont icon-xiangxia1 color_33 size30 p-left10 bold"></view>
				</view>
			</view>

			<view class="info">
				<view class="list">
					<text class="size36 color_33">{{ thisM.teamOrderNum }}</text>
					<text class="size28 color_33 m-top4">当月单量</text>
				</view>
				<view class="list">
					<text class="size36 color_33">{{ thisM.teamOrderMoney }}</text>
					<text class="size28 color_33 m-top4">当月业绩</text>
				</view>
				<view class="list">
					<text class="size36 color_33">{{ thisM.teamIncome }}</text>
					<text class="size28 color_33 m-top4">当月收益</text>
				</view>
			</view>

			<view class="chanList" v-for="(item, index) in pageData" :key="index">
				<view class="enBox">
					<text class="orderTxt">订单号：{{ item.order_code }}</text>
					<text class="orderTxt">金额：￥{{ item.payment }}</text>
					<text class="orderTxt">下单时间：{{ item.add_date }}</text>
				</view>
				<view class="earnings">
					<text class="color h6">收益</text>
					<text class="color size30">{{ item.income }}</text>
				</view>
			</view>
			<view class="p-top100 p-bot100" v-if="!pageData.length">
				<u-empty mode="list" text="暂无相关内容"></u-empty>
			</view>
		</view>

		<u-datetime-picker ref="datetimePicker" :show="show" v-model="value1" mode="year-month" :formatter="formatter"
			:maxDate="maxDate" @cancel="show = false" @confirm="confirm"></u-datetime-picker>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	export default {
		data() {
			return {
				thisM: '',
				pageData: [],
				page: 1,
				limit: 10,
				getMore: true,
				// 日期选择器
				show: false,
				value1: Number(new Date()),
				maxDate: Number(new Date()),
				monthData: ''
			}
		},
		computed: {
			...mapState(['color'])
		},
		onLoad() {
			this.monthData = this.$pop.tampToDate(new Date())
			this.OrderList()
		},
		onReady() {
			// 微信小程序需要用此写法
			this.$refs.datetimePicker.setFormatter(this.formatter)
		},
		methods: {
			OrderList() {
				this.$http.post({
					url: '/gsyxcxApi/getTeamOrderList',
					data: {
						scanDate: this.monthData + '-01',
						page: this.page,
						limit: this.limit
					}
				}).then((res) => {
					if (res.errcode != 100) return this.$Toast(res.msg)
					if (res.thisM) this.thisM = res.thisM
					const result = res.data || []
					this.pageData = this.page == 1 ? result : this.pageData.concat(result)
					if (result.length < this.limit) this.getMore = false
				})
			},
			confirm(e) {
				const result = this.$pop.tampToDate(e.value)
				this.value1 = e.value
				this.monthData = result
				this.show = false
				this.page = 1
				this.getMore = true
				this.OrderList()
			},
			formatter(type, value) {
				if (type === 'year') {
					return `${value}年`
				}
				if (type === 'month') {
					return `${value}月`
				}
				if (type === 'day') {
					return `${value}日`
				}
				return value
			}
		},
		onReachBottom() {
			if (!this.getMore) return
			this.page++
			this.OrderList()
		},
	}
</script>

<style lang="scss" scoped>
	.page {
		background-color: #f2f2f2;
	}

	.Wrapper {
		padding: 24rpx 30rpx;

		.info {
			background-color: #fff;
			display: flex;
			justify-content: space-between;
			padding: 24rpx;
			border-radius: 10rpx;
			margin-top: 24rpx;

			.list {
				display: flex;
				flex-direction: column;
				align-items: center;
			}
		}

		.chanList {
			margin: 24rpx auto 0;
			background-color: #fff;
			border-radius: 10rpx;
			padding: 24rpx;
			display: flex;
			align-items: center;

			.enBox {
				flex: 1;
				display: flex;
				flex-direction: column;

				.orderTxt {
					color: #333;
					font-size: 28rpx;
					line-height: 50rpx;
				}
			}

			.earnings {
				display: flex;
				flex-direction: column;
				text-align: right;
			}
		}
	}
</style>